package com.fm._4route;

import com.fm.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.util.Scanner;

public class SendMsg {
    public static void main(String[] args) throws Exception {
        System.out.println("请输⼊消息：");
        Scanner scanner = new Scanner(System.in);
        String msg = null;
        while (!"quit".equals(msg = scanner.nextLine())) {
            Connection connection = ConnectionUtil.getConnection();
            Channel channel = connection.createChannel();
            if (msg.startsWith("a")) {
                channel.basicPublish("ex2", "a", null, msg.getBytes());
            } else if (msg.startsWith("b")) {
                channel.basicPublish("ex2", "b", null, msg.getBytes());
            }
            System.out.println("发送：" + msg);
            channel.close();
            connection.close();
        }
    }
}